<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>模块管理</title>
    <link type="text/css" href="/media/admin/bootstrap/css/bootstrap.min.css?2" rel="stylesheet" />
    <link type="text/css" href="/media/admin/bootstrap/css/bootstrap-theme.min.css?2" rel="stylesheet" />
    <link type="text/css" href="/media/admin/css/views/layout.css?2" rel="stylesheet" />
    <script type="text/javascript" src="/media/admin/js/Scripts/jquery.min.js?2"></script>
    <script type="text/javascript" src="/media/admin/bootstrap/js/bootstrap.min.js?2"></script>
    <script type="text/javascript" src="/media/admin/js/model/common.js?2"></script>
    <script type="text/javascript" src="/media/admin/js/scripts/jquery.validate.min.js?2"></script>
    <script type="text/javascript" src="/media/admin/js/model/list.js?2"></script>
</head>
<body>
    <div class="panel panel-info">
                <div class="panel-heading">
                    <h3 class="panel-title">模块信息</h3>
                </div>
                <div class="well">
                    <form class="form-inline" role="form">
                        <div class="form-group">
                            <label class="control-label" for="name">用户组</label>
                            <select id="op_model">
                                <option value="" <?php if(empty($tag)):?> selected <?php endif;?>><?php echo $caption?></option>
                                 <option value="1" <?php if(!empty($tag)):?> selected <?php endif;?>>其他</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label class="control-label" for="name">模块名</label>
                            <input type="text" class="form-control" id="name" name="name" value="<?php echo $name?>"
                                   placeholder="请输入用户名">
                            <input type="hidden" id="userGroupId" name="usersid" value="<?php echo $usersid?>" />
                            <input type="hidden"  name="caption" value="<?php echo $caption?>" />
                            <input type="hidden"  name="tag" value="<?php echo $tag?>" />
                        </div>
                        <button type="submit" class="btn btn-info"> 查询</button>
                </form>
                    <div class="pagination">
                        <?php if(empty($tag)):?>
                        <button type="button" class="btn btn-primary" id="remove_model">
                            删除
                        </button>
                        <button type="button" class="btn btn-primary" id="save_model">
                            保存
                        </button>
                        <?php else:?>
                        <button type="button" class="btn btn-primary" id="add_model">
                            添加
                        </button>
                        <?php endif;?>
                    </div>
                </div>
                <div class="panel-body">
                    <table class="table table-condensed table-striped">
                        <thead>
                        <tr>
                            <th><input type="checkbox" class="rows_check" /> </th>
                            <th>编号</th>
                            <th>模块名称</th>
                            <th>父级名称</th>
                            <th>浏览</th>
                            <th>新增</th>
                            <th>编辑</th>
                            <th>删除</th>
                        </tr>
                        </thead>
                        <tbody>
                            <?php if(isset($userList['rows'])):?>
                            <?php foreach($userList['rows'] as $key=>$list):?>
                            <tr  class="data_list" data-umid="<?php echo $list['umid'] ?>">
                                <td><input type="checkbox" class="row_check" data-id="<?php echo $list['id'] ?>"  /></td>
                                <td><?php echo $key+1 ?></td>
                                <td><?php echo $list['caption'] ?></td>
                                <td><?php echo $list['pcaption'] ?></td>
                                <td>
                                    <select class="option look">
                                        <option value="0" <?php if($list['look']!="1"):?>selected="selected"<?php endif;?> >否</option>
                                        <option value="1" <?php if($list['look']=="1"):?>selected="selected" <?php endif;?>>是</option>
                                    </select>
                                </td>
                                <td>
                                    <select class="option add">
                                        <option value="0" <?php if($list['add']!="1"):?>selected="selected"<?php endif;?> >否</option>
                                        <option value="1" <?php if($list['add']=="1"):?>selected="selected" <?php endif;?>>是</option>
                                    </select>
                                </td>
                               <td>
                                    <select class="option edit">
                                        <option value="0" <?php if($list['edit']!="1"):?>selected="selected"<?php endif;?> >否</option>
                                        <option value="1" <?php if($list['edit']=="1"):?>selected="selected" <?php endif;?>>是</option>
                                    </select>
                                </td>
                                <td>
                                    <select class="option remove">
                                       <option value="0" <?php if($list['remove']!="1"):?>selected="selected"<?php endif;?> >否</option>
                                        <option value="1" <?php if($list['remove']=="1"):?>selected="selected" <?php endif;?>>是</option>
                                    </select>
                                </td>
                            </tr>
                            <?php endforeach; ?>
                        <?php endif;?>
                        </tbody>
                    </table>
                    <?php if($pages>1):?>
                        <div class="well well-sm" style="text-align: center"><?php echo HTML::getPageHtml($page,$pages,$url)?></div>
                    <?php endif;?>
                </div>
    </div>
    <script type="text/javascript">
        $("#op_model").on("change",function(){
            var value=$(this).find("option:selected").val();
            var url=window.location.href+"&tag="+value;
            window.location.href=url;
        });
        $("#add_model").on("click",function(){
            if($(".row_check:checked").size()==0){
                alert("对不起，请先选择记录!");
                return false;
            }
            else{
                if(!confirm('确认添加数据！')){
                    return false;
                }
                var id="";
                $(".row_check:checked").each(function(){
                    id=id+"'"+$(this).attr("data-id")+"',";
                });
                if(id.length>0){
                    id=id.substring(0,id.length-1);
                }
                var usersid=$("#userGroupId").val();
                md_common.postAjax('/admin/userGroup/addModel',{"usersid":usersid,"id":id},function(result){
                    if(result.info=="success"){
                        window.location.href= window.location.href;
                    }
                });
            }
        });
        $("#remove_model").on("click",function(){
            if($(".row_check:checked").size()==0){
                alert("对不起，请先选择记录!");
                return false;
            }
            else{
                if(!confirm('确认删除数据！')){
                    return false;
                }
                var id="";
                $(".row_check:checked").each(function(){
                    id=id+"'"+$(this).attr("data-id")+"',";
                });
                if(id.length>0){
                    id=id.substring(0,id.length-1);
                }
                var usersid=$("#userGroupId").val();
                md_common.postAjax('/admin/userGroup/removeUser',{"usersid":usersid,"id":id},function(result){
                    if(result.info=="success"){
                        window.location.href= window.location.href;
                    }
                });
            }
        });

        $(".option").on("change",function(){
            $(this).parent().parent().addClass("modify");
        });

        $("#save_model").on("click",function(){
            var data=[];
            $(".data_list.modify").each(function(){
                var list={
                    id:$(this).attr("data-umid"),
                    look:$(this).find(".look").val(),
                    add:$(this).find(".add").val(),
                    edit:$(this).find(".edit").val(),
                    remove:$(this).find(".remove").val()
                };
                data.push(list);
            });
            if(data.length>0){
                var data_str=JSON.stringify(data);
                md_common.postAjax("/admin/UserGroup/setLimit",{data:data_str},function(result){
                    if(result.info=="success"){
                        window.location.href= window.location.href;
                    }
                });
            }
        });
    </script>
</body>
</html>
